'use strict';
const dayjs = require("dayjs");

module.exports = app => {
    const { INTEGER, STRING, DATE, TINYINT, DECIMAL } = app.Sequelize;
    const Warehouse = app.model.define(
        'Warehouse',
        {
            id: { type: INTEGER, primaryKey: true, autoIncrement: true },
            warehouse_name: { type: STRING(100), allowNull: false, comment: '仓库名称' },
            warehouse_code: { type: STRING(50), allowNull: false, comment: '仓库编码' },
            contact_person: { type: STRING(50), allowNull: true, comment: '联系人' },
            contact_phone: { type: STRING(20), allowNull: true, comment: '联系电话' },
            province: { type: STRING(50), allowNull: true, comment: '省份' },
            city: { type: STRING(50), allowNull: true, comment: '城市' },
            district: { type: STRING(50), allowNull: true, comment: '区县' },
            address: { type: STRING(255), allowNull: true, comment: '详细地址' },
            area: { type: DECIMAL(10, 2), allowNull: true, comment: '面积（平方米）' },
            status: { type: TINYINT(1), defaultValue: 1, comment: '状态：0-禁用，1-启用' },
            create_time: {
                type: DATE,
                get() {
                    return dayjs(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss');
                }
            },
            update_time: {
                type: DATE,
                get() {
                    return dayjs(this.getDataValue('update_time')).format('YYYY-MM-DD HH:mm:ss');
                }
            }
        },
        {
            tableName: 'warehouse',
            timestamps: true,
            createdAt: 'create_time',
            updatedAt: 'update_time'
        }
    );

    return Warehouse;
};
